clear all
use "Directed Dyad example file.dta", replace


*** Note: In the two following examples, the created spatial effect variable has no values for country_i=="Japan"
*** since Japan has no contiguous neighbor in this dataset

* Create aggregate source contagion spatial lag variable with (undirected) contiguity variable as connectivity variable
spagg  patentsfiled, weight(contig_or_less1000km) source(country_i) target(country_j) time(year) form(source) link(ik) sename(SL_aggsource_W_contig) filename(SL_aggsource_W_contig)

* As above, but not row-standardized
spagg  patentsfiled, weight(contig_or_less1000km) source(country_i) target(country_j) time(year) form(source) link(ik) sename(SL_aggsource_W_contig_norowst) filename(SL_aggsource_W_contig_norowst) norowst

* Create aggregate target contagion spatial lag variable with directed exports from j to m as connectivity variable (exports from i to j are automatically transformed)
spagg  patentsfiled, weight(exports_i_to_j) source(country_i) target(country_j) time(year) form(target) link(jm) sename(SL_aggtarg_W_exports_j_to_m) filename(SL_aggtarg_W_exports_j_to_m)

* Create aggregate target contagion spatial lag variable with directed exports from m to j as connectivity variable (exports from i to j are automatically transformed)
spagg  patentsfiled, weight(exports_i_to_j) source(country_i) target(country_j) time(year) form(target) link(mj) sename(SL_aggtarg_W_exports_m_to_j) filename(SL_aggtarg_W_exports_m_to_j) 
